#ifndef SerializableObject_H
#define SerializableObject_H
#include <FastJsoncpp.h>

#include <string>

#include "json/value.h"

/**
 * @brief 对象序列化
 *
 */

#define SERIALIZABLE_OBJECT_D(CLASSNAME)                                     \
   private:                                                                  \
    std::string _className_##CLASSNAME = #CLASSNAME;                                     \
                                                                             \
   public:                                                                   \
    virtual std::string getClassName() const override { return _className_##CLASSNAME; } \
    virtual Json::Value toJsonObject() const override;                       \
    virtual bool fromJsonObject(const Json::Value& object) override;

class SerializableObject
{
   public:
    using Ptr = std::shared_ptr<SerializableObject>;
    SerializableObject() {}
    virtual ~SerializableObject() {}
    virtual std::string getClassName() const = 0;
    virtual Json::Value toJsonObject() const = 0;
    virtual bool fromJsonObject(const Json::Value& object) = 0;
    virtual bool fromString(const std::string& jsonstring) { return fromJsonObject(FastJsoncpp::parse(jsonstring)); }
    virtual std::string toString() const { return toJsonObject().toStyledString(); }

    virtual void updateObject(SerializableObject::Ptr other) {};
};
#endif